package pages;

import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import resources.Screenshot;
/**
 *
 * @author Einsiedler
 */
public class LoginPage {
    private WebDriver driver;
    private Screenshot screenshot = null;
    
    public LoginPage(WebDriver driver){
        this.driver = driver;
    }
 /**
  * Successful login in email
  * @param username 
  * @param userpassword
  * @return HomePage
  */   
    public HomePage login(String username, String userpassword){
//        Очистка полей ввода
        driver.findElement(By.id("Email")).clear();
        driver.findElement(By.id("Passwd")).clear();
//        
        driver.findElement(By.id("Email")).sendKeys(username);
        driver.findElement(By.id("Passwd")).sendKeys(userpassword);
        driver.findElement(By.id("signIn")).click();
        driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
        return new HomePage(driver);
    }
/**
 * Error login in email
 * @param username
 * @param userpassword
 * @return LoginPage
 */
    public LoginPage loginerror(String username, String userpassword){
        driver.findElement(By.id("Email")).sendKeys(username);
        driver.findElement(By.id("Passwd")).sendKeys(userpassword);
        driver.findElement(By.id("signIn")).click();
        screenshot = new Screenshot();
        String filescreen = "loginerror.png";
        screenshot.getscreenshot(driver,filescreen);
        return new LoginPage(driver);
    }

}
